package router

import (
	"fmt"
	"github.com/gin-gonic/gin"
	"net/http"
)

// RegisterHomeRouter home模块路由
func RegisterHomeRouter(g *gin.RouterGroup) {
	g.GET("/upload", func(c *gin.Context) {
		c.HTML(http.StatusOK, "home/upload.html", nil)
	})

	g.POST("/upload", func(c *gin.Context) {
		file, err := c.FormFile("file")
		if err != nil {
			c.String(http.StatusInternalServerError, "upload error")
		}
		err = c.SaveUploadedFile(file, "./upload/"+file.Filename)
		if err != nil {
			c.String(http.StatusInternalServerError, "upload error")
		}
		c.String(http.StatusOK, fmt.Sprintf("upload file: %s", file.Filename))
	})
}
